home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / gag / AlertPicture.lha / AlertPicture.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  4KB  |  111 lines

  1. /* ---------------------------------------------------------------------
  2.         Alert Picture - Display an IFF picture in a system alert.
  3.     by Tim Ferguson (Vision Beyond) of Alchemy Software Development.
  4.  
  5.   A small silly idea I had some years back but never got around to
  6.   implementing it, till now.....  This is VERY memory hungry and needs
  7.   six bytes for every pixel set on the source bitmap.  It takes ages to
  8.   display the picture.  Thanks to Jim Kent for his iff display routine
  9.   (VERY old, but hey, it works).
  10.  
  11.   As the text in a system alert can be placed anywhere inside the alert,
  12.   (possibly using the graphics library Move() and Text() functions) all I
  13.   do is place full stop characters in positions defined by a source bitmap.
  14.   As the full stop character is 2 by 2 pixels in size, this has the effect
  15.   of doubling the size of the bitmap.  Note that the alert is displayed in
  16.   hi-resolution, and with the doubling of the width of the pixels, it
  17.   effectively gives low-resolution width.
  18.  
  19.   You may do whatever you wish to this source, although credit to its
  20.   authour would be nice :)  It should compile with most C compliers,
  21.   although it may need a little modification on the header files.
  22.    --------------------------------------------------------------------- */
  23. #include <exec/types.h>
  24. #include <intuition/intuition.h>
  25. #include <clib/exec_protos.h>
  26. #include <clib/intuition_protos.h>
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. #include "work:Programing/IFF/jiff.h"
  30.  
  31. #define WIDTH            40
  32. #define HEIGHT            (256/2)
  33. #define X_OFFSET        2
  34. #define Y_OFFSET        2
  35.  
  36. struct ILBM_info iff_info;
  37. UBYTE *alertMsg;
  38.  
  39. struct Library *IntuitionBase;
  40.  
  41. /* --------------------------------------------------------------------- */
  42. void main(int argc, char **argv)
  43. {
  44. int line, col, x_pos, y_pos, loop;
  45. unsigned char *ch, val;
  46. UBYTE *ap;
  47.  
  48.     printf("Alert Picture by Tim Ferguson of Alchemy Software Development, 1993.\n\n");
  49.     printf("Generating image.....  This is gonna take a while.... Please wait. \n");
  50.  
  51.     if(argc < 2)
  52.         {
  53.         printf("Error in arguments.  Format:  `AlertPicture IFF_file'.\n");
  54.         return;
  55.         }
  56.  
  57.         /* ---------- Read IFF picture ---------- */
  58.     if(!(read_iff(argv[1], &iff_info, FALSE)))
  59.         {
  60.         printf("Error, cannot find an IFF file called `%s'.\n\n", argv[1]);
  61.         return;
  62.         }
  63.  
  64.         /* ---------- Check IFF picture dimensions ---------- */
  65.     if(iff_info.bitmap.BytesPerRow < WIDTH || iff_info.bitmap.Rows < HEIGHT)
  66.         {
  67.         free_planes(&iff_info.bitmap);
  68.         printf("Error in IFF dimensions.  Picture must be at least %d by %d pixels.\n\n", WIDTH*8, HEIGHT);
  69.         return;
  70.         }
  71.  
  72.         /* ---------- Allocate memory for alert message ---------- */
  73.     if(!(alertMsg = malloc((WIDTH*8*HEIGHT*6)+100)))
  74.         {
  75.         free_planes(&iff_info.bitmap);
  76.         printf("Error allocating memory.  Need %d bytes free space.\n", (WIDTH*8*HEIGHT*6)+100);
  77.         return;
  78.         }
  79.  
  80.         /* ---------- Generate alert message ---------- */
  81.     for(ap = alertMsg, ch = iff_info.bitmap.Planes[0], y_pos = Y_OFFSET, line = 0; line < HEIGHT-2; line++, y_pos += 2)
  82.         {
  83.         for(x_pos = X_OFFSET, col = 0; col < WIDTH; col++, ch++)
  84.             for(val = *ch, loop = 0; loop < 8; loop++, val = val << 1, x_pos += 2)
  85.                 if(val & 0x80)
  86.                     {
  87.                     *(ap++) = (x_pos>>8) & 0xff;        /* 2 byte X position */
  88.                     *(ap++) = x_pos & 0xff;
  89.                     *(ap++) = y_pos & 0xff;                /* 1 byte Y position */
  90.                     *(ap++) = '.';                            /* Text - 4 pixels   */
  91.                     *(ap++) = 0;                            /* Null termination  */
  92.                     *(ap++) = 1;                            /* Continued         */
  93.                     }
  94.  
  95.         ch += iff_info.bitmap.BytesPerRow - WIDTH;    /* add modulo for next scan */
  96.         }
  97.  
  98.     *(ap-1) = 0;
  99.     *ap = 0;
  100.  
  101.     free_planes(&iff_info.bitmap);
  102.  
  103.         /* ---------- Display alert message ---------- */
  104.     if(IntuitionBase = OpenLibrary("intuition.library",33))
  105.         {
  106.         DisplayAlert(RECOVERY_ALERT, alertMsg, HEIGHT*2);
  107.         CloseLibrary(IntuitionBase);
  108.         }
  109.     else printf("Error in opening the intuition library.\n\n");
  110. }
  111.